package com.ruoyi.web.controller.system.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.product.domain.ServiceBookProductOrders;
import com.ruoyi.system.product.service.IServiceBookProductOrdersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品进货单Controller
 * 
 * @author Administrator
 * @date 2021-03-06
 */
@Controller
@RequestMapping("/product/orders")
public class ServiceBookProductOrdersController extends BaseController
{
    private String prefix = "product/orders";

    @Autowired
    private IServiceBookProductOrdersService serviceBookProductOrdersService;

    @RequiresPermissions("product:orders:view")
    @GetMapping()
    public String orders()
    {
        return prefix + "/orders";
    }

    /**
     * 查询商品进货单列表
     */
    @RequiresPermissions("product:orders:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ServiceBookProductOrders serviceBookProductOrders)
    {
        startPage();
        List<ServiceBookProductOrders> list = serviceBookProductOrdersService.selectServiceBookProductOrdersList(serviceBookProductOrders);
        return getDataTable(list);
    }

    /**
     * 导出商品进货单列表
     */
    @RequiresPermissions("product:orders:export")
    @Log(title = "商品进货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ServiceBookProductOrders serviceBookProductOrders)
    {
        List<ServiceBookProductOrders> list = serviceBookProductOrdersService.selectServiceBookProductOrdersList(serviceBookProductOrders);
        ExcelUtil<ServiceBookProductOrders> util = new ExcelUtil<ServiceBookProductOrders>(ServiceBookProductOrders.class);
        return util.exportExcel(list, "orders");
    }

    /**
     * 新增商品进货单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品进货单
     */
    @RequiresPermissions("product:orders:add")
    @Log(title = "商品进货单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ServiceBookProductOrders serviceBookProductOrders)
    {
        return toAjax(serviceBookProductOrdersService.insertServiceBookProductOrders(serviceBookProductOrders));
    }

    /**
     * 修改商品进货单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ServiceBookProductOrders serviceBookProductOrders = serviceBookProductOrdersService.selectServiceBookProductOrdersById(id);
        mmap.put("serviceBookProductOrders", serviceBookProductOrders);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品进货单
     */
    @RequiresPermissions("product:orders:edit")
    @Log(title = "商品进货单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ServiceBookProductOrders serviceBookProductOrders)
    {
        return toAjax(serviceBookProductOrdersService.updateServiceBookProductOrders(serviceBookProductOrders));
    }

    /**
     * 删除商品进货单
     */
    @RequiresPermissions("product:orders:remove")
    @Log(title = "商品进货单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(serviceBookProductOrdersService.deleteServiceBookProductOrdersByIds(ids));
    }
}
